<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!DOCTYPE html>
<html lang="zh-cn" style="height: 100%">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
    <title><?=VIEW_TITLE?></title>
    <link href="<?php echo base_url('/assets/bs/'); ?>css/bootstrap.min.css" rel="stylesheet">
    <link href="<?php echo base_url('/assets/css/'); ?>my_common.css" rel="stylesheet">
    <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
</head>
<body>
<?php
$this->load->view('admin_header.php');
?>
<div class="container">
    <div id="main_div" style="max-width: 720px;margin: auto;">
        <table class="table table-striped" style="margin-bottom: 0;">
            <tr>
                <th>未领取邀请码
                    <div style="float: right;">
                        <button id="aa" type="button" class="btn btn-primary btn-xs" onclick="createCode()">新增激活码</button>
                        <span id="help" class="btn btn-xs glyphicon glyphicon-question-sign" data-toggle="tooltip"
                              data-placement="right" title="邀请码由系统随机生成,仅限使用一次,使用后立即失效"></span>
                    </div>
                </th>
            </tr>
        </table>
        <div id="scroll_div" style="overflow-y: scroll;overflow-x: hidden">
            <table class="table table-striped" id="code" >
                <tr style="display: none;">
                   <td></td>
                </tr>
            </table>
        </div>

    </div>
</div>
<?php
$this->load->view('footer.php');
?>
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<script src="<?php echo base_url('/assets/bs/'); ?>js/bootstrap.min.js"></script>
<script>
    var w_width = document.documentElement.clientWidth;
    var w_height = document.documentElement.clientHeight;
    var scroll_div_height = w_height - 300;
    $('#scroll_div').height(scroll_div_height + 'px');
        $(function () { $("[data-toggle='tooltip']").tooltip(); });
        $(function () { $("[data-toggle='popover']").popover(); });
//    $('#help').tooltip();
    function createCode() {
        $.ajax({
            url: '<?php echo site_url('/Administrator/createCode')?>',
            type: 'post',
            dataType: 'json',
            data: {},
            success: function (data) {
                if(data == 'success'){
                    getCode();
                }else{
                    alert(data);
                }
            }
        });
    }

    function getCode() {
        $.ajax({
            url: '<?php echo site_url('/Administrator/getCodeJson')?>',
            type: 'post',
            dataType: 'json',
            data: {},
            success: function (data) {
                var len = data.length;
                var html = '';
                for (var i = 0; i < len; i++) {
                    html += '<tr class="remove"><td>' + data[i]['code'] + '</td></tr>';
                }
                $('tr').remove('.remove');
                $('#code').append(html);
            }
        });
    }
    getCode();
</script>
</body>
</html>